<?php
/**
 * Created by PhpStorm.
 * User: lgm
 * Date: 2018/8/30
 * Time: 15:07
 */
namespace app\webapp\controller;

use mylib\Jssdk;

use think\Controller;
use think\Db;
use think\facade\Request;

class Index extends Controller
{
    public function index()
    {

        $jssdk = new Jssdk("wx42b1d8b494f60197", "37cc116d33b0df65942178f4a38862b8");
        $signPackage = $jssdk->GetSignPackage();

        //1、连表查询最新资讯
        $info = db('information')
            ->alias('a')
            ->join('info_category c','a.cat_id = c.cat_id')
            ->field('info_id,title,intro,img,pubtime,readcount,praise,c.cat_id,c.cat_title')
            ->order('info_id','DESC')
            ->limit(10)
            ->select();

        //2、24小时用户动态
        $dynamic = db('dynamic')
            ->alias('d')
            ->leftJoin('user u','d.u_id=u.u_id')
            ->field('dy_id,content,praise,	comment_num,media,pubtime,u.u_id,u.username,u.face,u.signature')
            ->order('dy_id','DESC')
            ->select();
//        pre($dynamic);

        $this->assign([
            'signPackage'=>$signPackage,
            'info' => $info,
            'dynamic'=>$dynamic
        ]);
        return view('index');
    }
    public function detail()
    {
        $iid = input('iid');
        $info = db('information')->where('info_id',$iid)->find();
        $info['formattime'] = date('Y-m-d H:i',$info['pubtime']);
        echo json_encode($info);
    }
}
